package com.github.dtkavin.bgq.utils

/**
  * Function: 重命名相关操作
  * #Author: john 
  * #Create: 2018 04 10 上午10:52 
  */
object RenameUtils {
  /**
    * 驼峰命名　－＞　下划线命名
    *
    * @param name
    * @return
    */
  def renameA2_a(name: String): String = {
    var newName: String = name
    for (i <- newName if i.isUpper) {
      newName = newName.replace(s"${i}", s"_${i.toLower}")
    }
    newName
  }

  /**
    * 下划线命名　－＞　驼峰命名，末尾为下滑线则删除
    *
    * @param name
    * @return
    */
  def rename_a2A(name: String): String = {
    var newName: String = name
    for (i <- newName if i == 95) {
      val index = newName.indexOf(i)
      index match {
        case idx if idx + 1 == newName.length => newName = newName.replace("_", "")
        case _ => {
          val ch = newName.charAt(index + 1)
          newName = newName.replace(s"_${ch}", s"${ch.toUpper}")
        }
      }

    }
    newName
  }

  def main(args: Array[String]): Unit = {
    var name = "a_bCde_fgHI"
    println(rename_a2A(name))
    //    println(renameA2_a(name))
  }
}
